'use strict';
import * as Koa from 'koa';
import { router, prefix } from '../middleware/router';
import { response } from '../middleware/result';
import { bannerService } from '../service/banner';

/** 首页轮播api对象 */
@prefix('banner')
class BannerController {
    /**
     * 
     * @api {post} /banner/query  查询首页图片
     * @apiDescription 查询banner
     * @apiName query
     * @apiParam {Number} type     类型 1：轮播图 2：优惠活动
     * @apiSampleRequest /banner/query
     * @apiGroup banner
     * @apiVersion 1.0.0
     */
    @router('/query', { method: 'post' })
    async query(ctx: Koa.Context) {
        let result = await bannerService.query(ctx.request.body.type);
        response(ctx, result);
    }
    /**
     * 
     * @api {post} /banner/save  保存banner信息
     * @apiDescription 保存banner信息
     * @apiName save
     * @apiParam (参数) {String} hrefurl   图片链接地址
     * @apiParam (参数) {String} img   图片
     * @apiParam (参数) {String} title   标题
     * @apiParam (参数) {Number} type    类型 1：轮播图 2：优惠活动
     * @apiParam (参数) {String} createuser    创建人
     * @apiSampleRequest /banner/save
     * @apiGroup banner
     * @apiVersion 1.0.0
     */
    @router('/save', { method: 'post' })
    async save(ctx: Koa.Context) {
        let result = await bannerService.save(ctx.request.body);
        response(ctx, result);
    }
    @router('/open/:id')
    async open(ctx: Koa.Context) {
        let result = await bannerService.open(ctx.params.id);
        response(ctx, result);
    }
    @router('/lock/:id')
    async lock(ctx: Koa.Context) {
        let result = await bannerService.lock(ctx.params.id);
        response(ctx, result);
    }
    @router('/querylist', { method: 'post' })
    async querylist(ctx: Koa.Context) {
        let result = await bannerService.querylist(ctx.request.body);
        response(ctx, result);
    }
    @router('/queryById/:id')
    async queryById(ctx: Koa.Context) {
        let result = await bannerService.queryById(ctx.params.id);
        response(ctx, result);
    }
    
}